package com.own.demo.blockchain.bitcoin;

import lombok.Data;

import java.util.Objects;

/**
 * @Author liwenfeng
 * @Description 交易
 * @Date 2023/07/17/14:26
 * @Version 1.0
 */
@Data
public class Transaction {
    // 交易唯一标识
    private String id;
    // 交易发送方
    private String sender;
    // 交易接收方
    private String recipient;
    // 交易金额
    private int amount;

    public Transaction() {
        super();
    }

    public Transaction(String id, String sender, String recipient, int amount) {
        super();
        this.id = id;
        this.sender = sender;
        this.recipient = recipient;
        this.amount = amount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {return true;}
        if (o == null || getClass() != o.getClass()) {return false;}
        Transaction that = (Transaction) o;
        return amount == that.amount && Objects.equals(id, that.id) && Objects.equals(sender, that.sender) && Objects.equals(recipient, that.recipient);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 :id.hashCode());
        return result;
    }
}
